package com.erbao.nettystudy.bio;

import java.io.IOException;
import java.net.Socket;

/**
 * @author CaoBaoYin
 * @since 2021/10/21 7:50
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("127.0.0.1", 8888);
        s.getOutputStream().write("HelloServer".getBytes());
        s.getOutputStream().flush();
        // 此行如果把  s.getOutputStream() 关掉，会造成下面代码无法read

        System.out.println("write over , waiting for msg back...");

        byte[] b = new byte[1024];
        int len = s.getInputStream().read(b);
        System.out.println(new String(b, 0, len));

        s.close();
    }
}
